<template>
  <article class="article-card">
    <RouterLink :to="`/article/${article.id}`" class="article-link">
      <div class="image-container">
        <img v-if="article.image" :src="article.image" :alt="article.title" class="article-image">
        <div v-else class="image-placeholder"></div>
        <div class="overlay"></div>
      </div>
      <div class="article-content">
        <div class="category-badge">{{ article.category }}</div>
        <h3>{{ article.title }}</h3>
        <div class="meta">
          <span class="date">{{ formatDate(article.date) }}</span>
          <span class="read-time">5分钟阅读</span>
        </div>
      </div>
    </RouterLink>
  </article>
</template>

<script setup>
import { defineProps } from 'vue'

const props = defineProps({
  article: {
    type: Object,
    required: true
  }
})

const formatDate = (dateString) => {
  return new Date(dateString).toLocaleDateString('zh-CN', {
    year: 'numeric',
    month: 'short',
    day: 'numeric'
  })
}
</script>

<style scoped>
.article-card {
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  transition: all 0.3s ease;
  background: white;
  height: 100%;
}

.article-card:hover {
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
}

.article-link {
  text-decoration: none;
  color: inherit;
  display: flex;
  flex-direction: column;
  height: 100%;
}

.image-container {
  position: relative;
  width: 100%;
  padding-top: 60%;
  overflow: hidden;
}

.article-image {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.5s ease;
}

.article-card:hover .article-image {
  transform: scale(1.05);
}

.image-placeholder {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(45deg, #f3f4f6, #e5e7eb);
}

.overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(to top, rgba(0,0,0,0.7) 0%, rgba(0,0,0,0) 50%);
}

.article-content {
  padding: 1.5rem;
  position: relative;
  z-index: 1;
}

.category-badge {
  background: rgba(255,255,255,0.9);
  color: #4f46e5;
  padding: 0.3rem 0.8rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  display: inline-block;
  margin-bottom: 1rem;
}

h3 {
  margin: 0 0 1rem;
  font-size: 1.3rem;
  line-height: 1.4;
  color: #2d3748;
}

.meta {
  display: flex;
  justify-content: space-between;
  color: #718096;
  font-size: 0.85rem;
  margin-top: 1rem;
}

/* 特色卡片样式 */
.featured-section .article-card {
  height: 400px;
}

.featured-section .article-content {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  color: white;
}

.featured-section h3 {
  color: white;
  font-size: 1.5rem;
}

.featured-section .meta {
  color: rgba(255,255,255,0.8);
}

.featured-section .category-badge {
  background: rgba(79, 70, 229, 0.9);
  color: white;
}
</style>